import { _decorator, Component } from 'cc';
import { AudioManager } from '../../framework/manager/AudioManager';
import { ResourceMgr } from '../../framework/manager/ResourceMgr';

const { ccclass } = _decorator;

/**
 * 音频
 */
@ccclass('AudioScene')
export class AudioScene extends Component {

    private isPlay: boolean = false;

    protected onLoad(): void {
        ResourceMgr.Instance.addButtonListen(this.node.getChildByName("MusicBtn"), this, this.onPlayMusic)
        ResourceMgr.Instance.addButtonListen(this.node.getChildByName("ClipBtn"), this, this.onPlayClip)
    }

    // 背景音乐
    private onPlayMusic() {
        if (this.isPlay) {
            AudioManager.Instance.stop()
            this.isPlay = false;
        } else {
            AudioManager.Instance.playMusic('audios/Start.wav')
            this.isPlay = true;
        }
    }

    /**
     * 音效
     */
    private onPlayClip() {
        // AudioManager.Instance.playOneShot("audios/Fire.wav")
    }

}